package com.ruoyi.system.task;

import com.ruoyi.system.service.IRoomService;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.beans.factory.annotation.Autowired;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Component
public class RoomBackupTask {
    private static final Logger log = LoggerFactory.getLogger(RoomBackupTask.class);

    @Autowired
    private IRoomService roomService;

    /**
     * 每天18点30分自动备份并清空房间信息
     */
    @Scheduled(cron = "0 30 18 * * ?")
    public void backupAndClearRoomTask() {
        log.info("[定时任务] 开始自动备份并清空房间信息");
        try {
            roomService.backupAndClearRoom();
            log.info("[定时任务] 房间信息备份并清空完成");
        } catch (Exception e) {
            log.error("[定时任务] 房间信息备份并清空失败", e);
        }
    }
} 